/*
 * Copyright (c) 2010 Nokia Corporation.
 */

// This Javascript function handles button press events on the app dialler keypad
function buttonPressed(op) {

    // End call if one is in progress and quit the app
    if (op == "X") {
        telephony.endCall();
        Qt.quit();
    }

    // Add a number to the display
    else if (op.toString().length==1 && (op >= "0" && op <= "9") ) {
        // Limit phone number to 12 digits so it not overflow the display in portrait mode
        if (display.text.toString().length >= 12) {
           return
        }
        else {
           if (display.text == " ") {
               display.text = op.toString();
           }
           else {
               display.text = display.text + op.toString()
           }
           return;
        }
    }
    // Delete last number from the display
    else if (op == back) {

        if (display.text.length == 1) {
            display.text = " ";
        }
        else {
            display.text = display.text.slice(0, -1)
        }
    }
    // Call the telephony object to start a phone call
    else if (op == "Call") {
        telephony.startCall(display.text);
    }
    // End the call
    else if (op == "End Call") {
        telephony.endCall();
    }
}

